package com.fourcitizens.playas.scrapper;

class PrintableBeach {
	private String _id;
	
	private String _province;
	private String _town;
	private String _name;
	private String _description;
	
	private int    _length;
	private int    _mediumWidth;
	private String _occupation;
	private String _urbanization;
	private boolean _promenade;
	
	private String _composition;
	private String _sandType;
	private String _bathingConditions;
	private boolean _anchorageArea;
	private boolean _nudist;
	
	private boolean _vegetation;
	private boolean _protectedArea;
	private boolean _blueFlag;

	private boolean _accessSignaling;
	private boolean _disabledAccess;
	
	private boolean _toilets;
	private boolean _showers;
	private boolean _phone;
	private boolean _paperBin;
	private boolean _cleaningService;
	private boolean _gateways;
	private boolean _umbrellasRental;
	private boolean _sunbedRental;
	private boolean _yatchRental;
	private boolean _spaKiosks;
	private boolean _yatchClub;
	private boolean _divingArea;
	
	private String _latitude;
	private String _longitude;
	
	public PrintableBeach(String province, String town, String name, String description, int length, int mediumWidth, String occupation, String urbanization, boolean promenade, 
			String composition, String sandType, String bathingConditions, boolean anchorageArea, boolean nudist, boolean vegetation, boolean protectedArea, boolean blueFlag, 
			boolean accessSignaling, boolean disabledAccess, boolean toilets, boolean showers, boolean phone, boolean paperBin, boolean cleaningService, boolean gateways,
			boolean umbrellasRental, boolean sunbedRental, boolean yatchRental, boolean spaKiosks, boolean yatchClub, boolean divingArea) {
		_id = generateId();
		_province = province;
		_town = town;
		_name = name;
		_description = description;
		_length = length;
		_mediumWidth = mediumWidth;
		_occupation = occupation;
		_urbanization = urbanization;
		_promenade = promenade;
		_composition = composition;
		_sandType = sandType;
		_bathingConditions = bathingConditions;
		_anchorageArea = anchorageArea;
		_nudist = nudist;
		_vegetation = vegetation;
		_protectedArea = protectedArea;
		_blueFlag = blueFlag;
		_accessSignaling = accessSignaling;
		_disabledAccess = disabledAccess;
		_toilets = toilets;
		_showers = showers;
		_phone = phone;
		_paperBin = paperBin;
		_cleaningService = cleaningService;
		_gateways = gateways;
		_umbrellasRental = umbrellasRental;
		_sunbedRental = sunbedRental;
		_yatchRental = yatchRental;
		_spaKiosks = spaKiosks;
		_yatchClub = yatchClub;
		_divingArea = divingArea;
		_latitude = null;
		_longitude = null;
	}
	
	private static int idCounter = 0;
	
	private static String generateId() {
		idCounter++;
		String id = Integer.toString(idCounter);
		StringBuffer sb = new StringBuffer();
		for (int i = 4; i > id.length(); i--) 
			sb.append('0');
		sb.append(id);
		return sb.toString();
	}
	
	public String getId() {
		return _id;
	}
	
	public String getName() {
		return _name;
	}
	
	public String getTown() {
		return _town;
	}
	
	public String getProvince() {
		return _province;
	}
	
	public String getCountry() {
		return "Spain";
	}
	
	public void setLaitude(String latitude) {
		_latitude = latitude;
	}
	
	public void setLongitude(String longitude) {
		_longitude = longitude;
	}
	
	public String toCSVRow() {
		StringBuffer sb = new StringBuffer();
		appendFormatedString(sb, _id, ';');
		appendFormatedString(sb, _province, ';');
		appendFormatedString(sb, _town, ';');
		appendFormatedString(sb, _name, ';');
		appendFormatedString(sb, _description, ';');
		appendFormatedInt(sb, _length, ';');
		appendFormatedInt(sb, _mediumWidth, ';');
		appendFormatedBoolean(sb, _promenade, ';');
		appendFormatedBoolean(sb, _anchorageArea, ';');
		appendFormatedBoolean(sb, _nudist, ';');
		appendFormatedString(sb, _occupation, ';');
		appendFormatedString(sb, _urbanization, ';');
		appendFormatedString(sb, _composition, ';');
		appendFormatedString(sb, _sandType, ';');
		appendFormatedString(sb, _bathingConditions, ';');
		appendFormatedBoolean(sb, _vegetation, ';');
		appendFormatedBoolean(sb, _blueFlag, ';');
		appendFormatedBoolean(sb, _protectedArea, ';');	
		appendFormatedBoolean(sb, _accessSignaling, ';');
		appendFormatedBoolean(sb, _disabledAccess, ';');
		appendFormatedBoolean(sb, _toilets, ';');
		appendFormatedBoolean(sb, _showers, ';');
		appendFormatedBoolean(sb, _phone, ';');
		appendFormatedBoolean(sb, _paperBin, ';');
		appendFormatedBoolean(sb, _cleaningService, ';');
		appendFormatedBoolean(sb, _gateways, ';');
		appendFormatedBoolean(sb, _umbrellasRental, ';');
		appendFormatedBoolean(sb, _sunbedRental, ';');
		appendFormatedBoolean(sb, _yatchRental, ';');
		appendFormatedBoolean(sb, _spaKiosks, ';');
		appendFormatedBoolean(sb, _yatchClub, ';');
		appendFormatedBoolean(sb, _divingArea, ';');
		if (_latitude != null)
			appendFormatedString(sb, _latitude, ';');
		else
			appendFormatedString(sb, "", ';');
		if (_longitude != null)
			appendFormatedString(sb, _longitude, ';');
		else
			appendFormatedString(sb, "", ';');
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		return sb.toString();
	}
	
	private static void appendFormatedString (StringBuffer sb, String s, char separator) {
		sb.append('"');
		sb.append(s);
		sb.append('"');
		sb.append(separator);
	}

	private static void appendFormatedInt (StringBuffer sb, int i, char separator) {
		sb.append('"');
		sb.append(i);
		sb.append('"');
		sb.append(separator);
	}

	private static void appendFormatedBoolean (StringBuffer sb, boolean b, char separator) {
		sb.append('"');
		sb.append(b);
		sb.append('"');
		sb.append(separator);
	}
}
